package cn.itcast.hotel.controller;

import cn.itcast.hotel.pojo.PageResult;
import cn.itcast.hotel.pojo.RequestParams;
import cn.itcast.hotel.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hotel")
@Slf4j
public class hotelController {
    @Autowired
    private IHotelService iHotelService;

    /**
     * 不含countdownLunch 批量导入
     *
     * @return
     */
    @GetMapping("/getDocAll")
    public String hotelPool() {
        iHotelService.getDoc();
        return "{'success':'成功'}";
    }

    /**
     * 使用多线程解决批量导入数据到es中 含有countdownLunch
     *
     * @return
     */
    @GetMapping("/getDocAll2")
    public String hotelPool2() {
        iHotelService.getDoc2();
        return "{'success':'成功'}";
    }
    /*
     * 黑马旅游项目
     */

    /**
     * 酒店的搜索和分页 以及 条件的过滤 我周边的酒店
     */
    @PostMapping("/list")
    public PageResult list(@RequestBody RequestParams requestParams) throws IOException {
        return iHotelService.searchHotel(requestParams);
    }

    /**
     * 酒店结果过滤filters
     */
    @PostMapping("/filters1")
    public Map<String, List<String>> getFilters1(@RequestBody RequestParams requestParams) {
        return iHotelService.filtersHotel(requestParams);
    }

    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params) {
        return iHotelService.filters(params);
    }

    /**
     * 搜索框的自动补全功能
     */
    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String prefix) {
        log.info("查询的前缀是：{} ", prefix);
        return iHotelService.suggestion(prefix);
    }
}
